<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_GET["id"])) {
    exit("需要传入有效的参数！");
}

$id = $_GET["id"];

// -----------------------------------------------------------------------------
// 时区设置
// -----------------------------------------------------------------------------

date_default_timezone_set($region);

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath;
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$linkDetails = $db->getLinkDetailsById($id);
extract($linkDetails);

// 描述
if (empty($description)) {
    $description = "未填写。";
}

// 分类标题
$category = $db->getCategoryDetailsById($categoryId)["title"];

// 点击次数
if (is_null($timesOfClick)) {
    $timesOfClick = 0;
}

/* 时间相关 */

$timeCreate = date("Y-m-d H:i:s", $timeCreate);
$timeLastEdit = date("Y-m-d H:i:s", $timeLastEdit);

if (is_null($timeLastClick)) {
    $timeLastClick = "暂无记录。";
} else {
    $timeLastClick = date("Y-m-d H:i:s", $timeLastClick);
}

if (is_null($timeLastMove)) {
    $timeLastMove = "暂无记录。";
} else {
    $timeLastMove = date("Y-m-d H:i:s", $timeLastMove);
}


echo <<<BBB
<table class="table table-striped">

    <thead>
        <tr>
            <td>key</td>
            <td>value</td>
        </tr>
    </thead>
    
    <tbody class="text-break">
    
        <tr>
            <td>id</td>
            <td>$id</td>
        </tr>
        
        <tr>
            <td>title</td>
            <td>$title</td>
        </tr>
        
        <tr>
            <td>url</td>
            <td>$url</td>
        </tr>
            
        <tr>
            <td>分类</td>
            <td>$category</td>
        </tr>
                
        <tr>
            <td>分类ID</td>
            <td>$categoryId</td>
        </tr>       
        
        <tr>
            <td>描述</td>
            <td>$description</td>
        </tr>
                
        <tr>
            <td>排序号</td>
            <td>$sortNumber</td>
        </tr>
                        
        <tr>
            <td>创建时间</td>
            <td>$timeCreate</td>
        </tr>
        
                        
        <tr>
            <td>最后编辑时间</td>
            <td>$timeLastEdit</td>
        </tr>
                        
        <tr>
            <td>最后移动时间</td>
            <td>$timeLastMove</td>
        </tr>
        
        <tr>
            <td>最后点击时间</td>
            <td>$timeLastClick</td>
        </tr>
                        
        <tr>
            <td>总点击次数</td>
            <td>$timesOfClick</td>
        </tr>
        
    </tbody>
</table>
BBB;
